home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1458.dms / var1458.adf / IDCMP / Example4.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  7KB  |  191 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: IDCMP                       Tulevagen 22       */
  8. /* File:    Example4.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This program explains how to use the IDCMP flag SIZEVERIFY. */
  21.  
  22.  
  23.  
  24. #include <intuition/intuition.h>
  25.  
  26.  
  27.  
  28. struct IntuitionBase *IntuitionBase;
  29.  
  30.  
  31.  
  32. /* Declare a pointer to a Window structure: */ 
  33. struct Window *my_window;
  34.  
  35. /* Declare and initialize your NewWindow structure: */
  36. struct NewWindow my_new_window=
  37. {
  38.   50,             /* LeftEdge    x position of the window. */
  39.   25,             /* TopEdge     y positio of the window. */
  40.   320,            /* Width       320 pixels wide. */
  41.   100,            /* Height      100 lines high. */
  42.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  43.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  44.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user: */
  45.                   /*             selects the Close window gad.            */
  46.  
  47.   SIZEVERIFY,     /*             We will also recieve a verifying message */
  48.                   /*             when the user resizes the window.        */
  49.                   /*             However, the window will change size     */
  50.                   /*             first when we have replied.              */
  51.  
  52.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  53.   WINDOWCLOSE|    /*             Close Gadget. */
  54.   WINDOWDRAG|     /*             Drag gadget. */
  55.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  56.   WINDOWSIZING|   /*             Sizing Gadget. */
  57.   ACTIVATE,       /*             The window should be Active when opened. */
  58.   NULL,           /* FirstGadget No gadgets connected to this window. */
  59.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  60.   "RESIZABLE WINDOW", /* Title   Title of the window. */
  61.   NULL,           /* Screen      Connected to the Workbench Screen. */
  62.   NULL,           /* BitMap      No Custom BitMap. */
  63.   100,            /* MinWidth    We will not allow the window to become */
  64.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  65.   400,            /* MaxWidth    than 400 x 200. */
  66.   200,            /* MaxHeight */
  67.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  68. };
  69.  
  70.  
  71.  
  72. /*************************************************************************/
  73. /* Extra information:                                                    */
  74. /* When we recieve a SIZEVERIFY message we may finish off with something */
  75. /* before we allow Intuition to resize the window. The window will first */
  76. /* be resized when we have replied.                                      */
  77. /*************************************************************************/
  78.  
  79.  
  80.  
  81. main()
  82. {
  83.   /* Boolean variable used for the while loop: */
  84.   BOOL close_me;
  85.  
  86.   ULONG class; /* IDCMP flag. */
  87.  
  88.   /* Pointer to an IntuiMessage structure: */
  89.   struct IntuiMessage *my_message;
  90.  
  91.  
  92.  
  93.   /* Before we can use Intuition we need to open the Intuition Library: */
  94.   IntuitionBase = (struct IntuitionBase *)
  95.     OpenLibrary( "intuition.library", 0 );
  96.   
  97.   if( IntuitionBase == NULL )
  98.     exit(); /* Could NOT open the Intuition Library! */
  99.  
  100.  
  101.  
  102.   /* We will now try to open the window: */
  103.   my_window = (struct Window *) OpenWindow( &my_new_window );
  104.   
  105.   /* Have we opened the window succesfully? */
  106.   if(my_window == NULL)
  107.   {
  108.     /* Could NOT open the Window! */
  109.     
  110.     /* Close the Intuition Library since we have opened it: */
  111.     CloseLibrary( IntuitionBase );
  112.  
  113.     exit();  
  114.   }
  115.  
  116.  
  117.  
  118.   /* We have opened the window, and everything seems to be OK. */
  119.  
  120.   printf("Try to resize the window!\n\n");
  121.  
  122.  
  123.  
  124.   close_me = FALSE;
  125.  
  126.   /* Stay in the while loop until the user has selected the Close window */
  127.   /* gadget: */
  128.   while( close_me == FALSE )
  129.   {
  130.     /* Wait until we have recieved a message: */
  131.     Wait( 1 << my_window->UserPort->mp_SigBit );
  132.  
  133.  
  134.     /* As long as we can collect messages successfully we stay in the */
  135.     /* while-loop: */
  136.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  137.     {
  138.       /* After we have successfully collected the message we can read */
  139.       /* it, and save any important values which we maybe want to check */
  140.       /* later: */
  141.       class = my_message->Class;  /* IDCMP flag. */
  142.  
  143.  
  144.       /* Check if we have recieved a SIZEVERIFY message: */
  145.       if( class == SIZEVERIFY )
  146.       {
  147.         /* The user tries to resize the window. However, it will first */
  148.         /* change size when we have replied, so we may finish of with  */
  149.         /* something before. We will now take a little pause, just to  */
  150.         /* show that we can control the resizing of the window:        */
  151.         printf("So you tried to resize the window! Tough luck!\n");
  152.         printf("Here I decide when you may resize it, and I want\n");
  153.         printf("to take a pause...\n");
  154.       
  155.         /* Wait 2 seconds: */
  156.         Delay( 2 * 50 );
  157.         
  158.         printf("OK! You may now resize the window.\n\n");
  159.         /* Once we reply the window will be resized. */
  160.       }
  161.  
  162.  
  163.       /* After we have read it we reply as fast as possible: */
  164.       /* REMEMBER! Do never try to read a message after you have replied! */
  165.       /* (Some other process has maybe changed it.) */
  166.       ReplyMsg( my_message );
  167.  
  168.  
  169.       /* Check which IDCMP flag was sent: */
  170.       switch( class )
  171.       {
  172.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  173.                close_me=TRUE;
  174.                break;
  175.       }
  176.     }
  177.   }
  178.  
  179.  
  180.  
  181.   /* Close the window: */
  182.   CloseWindow( my_window );
  183.  
  184.  
  185.  
  186.   /* Close the Intuition Library: */
  187.   CloseLibrary( IntuitionBase );
  188.   
  189.   /* THE END */
  190. }
  191.